package com.crm.system.controller.returnMoney;

import com.crm.common.model.DataResponse;
import com.crm.common.model.DhPageInfo;
import com.crm.common.model.DhResponse;
import com.crm.common.model.Enum.ResponseCodeEnum;
import com.crm.model.entity.returnMoney.ReturnMoneyExamine;
import com.crm.model.qo.returnMoney.ReturnMoneyExamineQO;
import com.crm.model.qo.returnMoney.RmExamineRecordQO;
import com.crm.model.vo.returnMoney.ReturnMoneyExamineVO;
import com.crm.model.vo.returnMoney.RmExamineRecordVO;
import com.crm.system.service.returnMoney.ReturnMoneyExamineService;
import com.crm.system.service.returnMoney.RmExamineRecordService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**
 * 
 * @Author xielinqi
 * @Date 3:51 下午 2021/12/2
 */
@RestController
@RequestMapping("/returnMoneyExamine")
@Slf4j
public class ReturnMoneyExamineController {

    @Autowired
    private ReturnMoneyExamineService returnMoneyExamineService;
    @Autowired
    private RmExamineRecordService rmExamineRecordService;

    /**
     * 回款审核列表
     * @Param request
     * @Param pageIndex
     * @Param pageSize
     * @Param bankFlowExamineQO
     * @Author xielinqi
     * @Date 11:19 上午 2021/12/3
     */
    @PostMapping("/queryList")
    public DataResponse queryList(HttpServletRequest request,
                                                   @RequestParam(value = "pageIndex", required = false) Integer pageIndex,//页码
                                                   @RequestParam(value = "pageSize", required = false) Integer pageSize,//分页大小
                                                   ReturnMoneyExamineQO returnMoneyExamineQO
    ){
        try{
            DhPageInfo<ReturnMoneyExamineVO> list = returnMoneyExamineService.selectPageList(pageIndex, pageSize, returnMoneyExamineQO);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),list);
        }catch(Exception e){
            log.error("order customerOrderBackMoneyList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }

    /**
     * 审核
     * @Param returnMoneyExamine
     * @Author xielinqi
     * @Date 10:08 上午 2021/12/6
     */
    @PostMapping("/examine")
    public DataResponse examine(ReturnMoneyExamine returnMoneyExamine){
        return returnMoneyExamineService.examine(returnMoneyExamine);
    }

    /**
     * 审核详情
     * @Param examineId
     * @Author xielinqi
     * @Date 11:50 上午 2021/12/6
     */
    @PostMapping("/queryDetails")
    public DataResponse queryDetails(String examineId){
        return new DhResponse(ResponseCodeEnum.OK.getResponseCode(), returnMoneyExamineService.getDetails(examineId));
    }

    /**
     * 上传材料
     * @Param examineId
     * @Param file
     * @Author xielinqi
     * @Date 4:06 下午 2021/12/6
     */
    @PostMapping("/uploadMaterial")
    public DataResponse uploadMaterial(String examineId, @RequestParam(value = "file", required = false) MultipartFile file) {
        return returnMoneyExamineService.uploadMaterial(examineId, file);
    }

    /**
     * 回款审核记录列表
     * @Param request
     * @Param pageIndex
     * @Param pageSize
     * @Param rmExamineRecordQO
     * @Author xielinqi
     * @Date 10:29 上午 2021/12/13
     */
    @PostMapping("/queryExamineList")
    public DataResponse queryExamineList(HttpServletRequest request,
                                  @RequestParam(value = "pageIndex", required = false) Integer pageIndex,//页码
                                  @RequestParam(value = "pageSize", required = false) Integer pageSize,//分页大小
                                  RmExamineRecordQO rmExamineRecordQO
    ){
        try{
            DhPageInfo<RmExamineRecordVO> list = rmExamineRecordService.selectPageList(pageIndex, pageSize, rmExamineRecordQO);
            return new DhResponse(ResponseCodeEnum.OK.getResponseCode(),list);
        }catch(Exception e){
            log.error("order customerOrderBackMoneyList error:", e);
            return new DhResponse(ResponseCodeEnum.ERROR.getResponseCode());
        }
    }
}
